package com.fengze.business.controller;

import com.fengze.business.domain.ContractInfo;
import com.fengze.business.domain.InquiryRecord;
import com.fengze.business.domain.ProjectInfo;
import com.fengze.business.domain.RemindInfo;
import com.fengze.business.mapper.InquiryManifestMapper;
import com.fengze.business.mapper.InquiryRecordMapper;
import com.fengze.business.service.DashBoardService;
import com.fengze.business.service.IRemindInfoService;
import com.fengze.business.vo.ContractInfoVO;
import com.fengze.business.vo.InquiryRecordVO;
import com.fengze.business.vo.ProjectInfoVO;
import com.fengze.common.core.controller.BaseController;
import com.fengze.common.core.domain.AjaxResult;
import com.fengze.common.core.page.TableDataInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 首页统计接口控制类
 */
@RestController
@RequestMapping("/dashboard")
public class DashboardController extends BaseController {


    @Autowired
    private DashBoardService dashBoardService;

    @Autowired
    private IRemindInfoService remindInfoService;

    @Autowired
    private InquiryRecordMapper inquiryRecordMapper;

    /**
     *
     * 统计数量接口
     * @return
     */

    @GetMapping("/staticsNum")
    public AjaxResult staticsNum(){
        return AjaxResult.success(dashBoardService.queryStaticsNum());
    }

    /**
     * 询价信息列表
     * @param record
     * @return
     */

    @GetMapping("/inquiry/list")
    public TableDataInfo inquiryList(InquiryRecord record)
    {
        startPage();
        List<InquiryRecordVO> list = dashBoardService.queryInquiryList(record);
        // 设置信息状态
        for (InquiryRecordVO inquiryRecordVO : list) {
            Integer maxInquiryNumber = inquiryRecordMapper.selectMaxInquiryNumber(inquiryRecordVO.getId());

            if(maxInquiryNumber == null || maxInquiryNumber == 0){
                inquiryRecordVO.setStatus(0);
            }else{
                inquiryRecordVO.setStatus(1);
            }
            
        }

        return getDataTable(list);
    }

    @GetMapping("/inquiry/listOld")
    public TableDataInfo inquiryListOld(InquiryRecord record)
    {
        startPage();
        List<InquiryRecordVO> list = dashBoardService.query(record);
        return getDataTable(list);
    }

    /**
     * 项目信息列表
     * @param contractInfo
     * @return
     */
    @GetMapping("/project/list")
    public TableDataInfo projecList(ProjectInfo projectInfo)
    {
        startPage();
        List<ProjectInfoVO> list = dashBoardService.queryProjectList(projectInfo);
        return getDataTable(list);
    }

    /**
     * 合同信息列表
     * @param contractInfo
     * @return
     */
    @GetMapping("/contract/list")
    public TableDataInfo contractList(ContractInfo contractInfo)
    {
        startPage();
        List<ContractInfoVO> list = dashBoardService.queryContractList(contractInfo);
        return getDataTable(list);
    }


    /**
     * 提醒信息列表
     * @param remindInfo
     * @return
     */
    @GetMapping("/remind/list")
    public TableDataInfo remindList(RemindInfo remindInfo)
    {
        startPage();
        List<RemindInfo> list = remindInfoService.selectRemindInfoList(remindInfo);
        return getDataTable(list);
    }
}
